package com.example.mybatis.controller;

import com.example.mybatis.entity.SysTestEntity;
import com.example.mybatis.exception.JsonException;
import com.example.mybatis.service.SysTestService;
import com.example.mybatis.vo.ApiResponse;
import com.example.mybatis.vo.Status;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ThinkPad
 * Date: 2021-04-25 19:17
 * This is my work in reachauto code.
 * mail:chenxiangning@reachauto.com
 * Description:
 */

@Slf4j
@RestController
@RequestMapping("/sys_tests")
public class SysTestController {

    @Autowired
    private SysTestService sysTestService;


    @RequestMapping(value = "test-json-error", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public ApiResponse test() {
        throw new JsonException(Status.UNKNOWN_ERROR);
    }

    @RequestMapping(value = "", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public ApiResponse findAll() {

        return ApiResponse.success(sysTestService.list());
    }


    @RequestMapping(value = "", method = RequestMethod.POST, produces = {MediaType.APPLICATION_JSON_VALUE})
    public ApiResponse save(@RequestBody SysTestEntity sysTestEntity) {
        boolean boo = sysTestService.save(sysTestEntity);
        log.info("sysTest:{}", sysTestEntity);
        return ApiResponse.success(boo);
    }

}
